#!/usr/bin/env python

import unittest

from transactionmanager import TransactionManager
import rawdb


class TransactionManager_Test( unittest.TestCase ):
    def setUp( self ):
        self.tm = TransactionManager()
        self.db = rawdb.singleton()
        self.db.clear()
    # setUp()


    def testBegin( self ):
        self.tm.begin()
    # testBegin()


    def testEnd( self ):
        tid = self.tm.begin()
        sc = self.tm.get_shallow_copy( tid )

        sc.set( 1, 1 )
        sc.set( 2, 2 )
        
        self.tm.end( tid )

        self.assertEqual( self.db.get( 1 ), 1 )
        self.assertEqual( self.db.get( 2 ), 2 )
    # testEnd()


    def testAbort( self ):
        self.db.set( 1, 0 )

        tid = self.tm.begin()
        sc = self.tm.get_shallow_copy( tid )

        sc.set( 1, 1 )
        
        self.tm.abort( tid )

        self.assertEqual( self.db.get( 1 ), 0 )
    # testAbort()
# TransactionManager_Test



if __name__ == "__main__":
    unittest.main()
# endif
